package com.yunshan.mp.service.impl;

import com.yunshan.common.utils.DateUtils;
import com.yunshan.mp.domain.MpIndexPreview;
import com.yunshan.mp.mapper.MpIndexPreviewMapper;
import com.yunshan.mp.service.IMpIndexPreviewService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 预览页配置Service业务层处理
 * 
 * @author yunshan
 * @date 2025-01-20
 */
@Service
public class MpIndexPreviewServiceImpl implements IMpIndexPreviewService 
{
    @Autowired
    private MpIndexPreviewMapper mpIndexPreviewMapper;

    /**
     * 查询预览页配置
     * 
     * @param id 预览页配置主键
     * @return 预览页配置
     */
    @Override
    public MpIndexPreview selectMpIndexPreviewById(Long id)
    {
        return mpIndexPreviewMapper.selectMpIndexPreviewById(id);
    }

    /**
     * 查询预览页配置列表
     * 
     * @param mpIndexPreview 预览页配置
     * @return 预览页配置
     */
    @Override
    public List<MpIndexPreview> selectMpIndexPreviewList(MpIndexPreview mpIndexPreview)
    {
        return mpIndexPreviewMapper.selectMpIndexPreviewList(mpIndexPreview);
    }

    /**
     * 新增预览页配置
     * 
     * @param mpIndexPreview 预览页配置
     * @return 结果
     */
    @Override
    public int insertMpIndexPreview(MpIndexPreview mpIndexPreview)
    {
        //判断上下架时间
        if (mpIndexPreview.getOnTime() != null && mpIndexPreview.getOffTime() != null) {
            if (mpIndexPreview.getOnTime().before(DateUtils.getNowDate()) && mpIndexPreview.getOffTime().after(DateUtils.getNowDate())) {
                mpIndexPreview.setStatus(0);
            } else if (mpIndexPreview.getOffTime().before(DateUtils.getNowDate())) {
                mpIndexPreview.setStatus(1);
            }
        }
        mpIndexPreview.setCreateTime(DateUtils.getNowDate());
        return mpIndexPreviewMapper.insertMpIndexPreview(mpIndexPreview);
    }

    /**
     * 修改预览页配置
     * 
     * @param mpIndexPreview 预览页配置
     * @return 结果
     */
    @Override
    public int updateMpIndexPreview(MpIndexPreview mpIndexPreview)
    {
        mpIndexPreview.setUpdateTime(DateUtils.getNowDate());
        return mpIndexPreviewMapper.updateMpIndexPreview(mpIndexPreview);
    }

    /**
     * 批量删除预览页配置
     * 
     * @param ids 需要删除的预览页配置主键
     * @return 结果
     */
    @Override
    public int deleteMpIndexPreviewByIds(Long[] ids)
    {
        return mpIndexPreviewMapper.deleteMpIndexPreviewByIds(ids);
    }

    /**
     * 删除预览页配置信息
     * 
     * @param id 预览页配置主键
     * @return 结果
     */
    @Override
    public int deleteMpIndexPreviewById(Long id)
    {
        return mpIndexPreviewMapper.deleteMpIndexPreviewById(id);
    }

    @Override
    public MpIndexPreview selectMpIndexPreview() {
        return mpIndexPreviewMapper.selectMpIndexPreview();
    }

    @Override
    public int updateMpIndexPreviewStatus(Integer status) {
        return mpIndexPreviewMapper.updateMpIndexPreviewStatus(status);
    }
}
